---
id: "switch"
keywords: ["switch", "pattern", "match"]
name: "switch"
summary: "This is the `switch` expression keyword."
category: "languageconstructs"
---

A `switch` expression allows you to match / destructure almost any kind of value (array, list, records, strings, numbers, variants, etc). Each branch (pattern) of a `switch` expression must return a value of the same type.

### Example

<CodeTab labels={["ReScript", "JS Output"]}>

```res
type shape = Circle(float) | Square(float)

let shape = Square(3.0)

let message = switch shape {
| Circle(radius) => "Circle with radius " ++ Float.toString(radius)
| Square(length) => "Square with sides of length " ++ Float.toString(length)
}
```

```js
var shape = {
  TAG: "Square",
  _0: 3.0,
};

var message;

message =
  shape.TAG === "Circle"
    ? "Circle with radius " + (3.0).toString()
    : "Square with sides of length " + (3.0).toString();
```

</CodeTab>

### References

- [Switch Based on Shape of Data](../docs/manual/pattern-matching-destructuring.mdx#switch-based-on-shape-of-data)
